package entity.http;


import java.util.Map;

public class HttpResponseEntity extends HttpEntity {
    private Integer responseCode;

    public int getResponseCode(){
        if(responseCode == null){
            String code = this.target.substring(this.target.indexOf(" ") + 1, this.target.indexOf(" ") + 4
            );
            responseCode = Integer.parseInt(code);
        }
        return responseCode;
    }

    @Override
    public String toString(){
        StringBuilder sb = new StringBuilder();
        sb.append(this.target);
        sb.append("\r\n");
        for (Map.Entry<String, String> entry : this.headers.entrySet()){
            sb.append(entry.getKey() + ":" + entry.getValue());
            sb.append("\r\n");
        }
//        sb.append(new String(this.body, 0, body.length));

        return sb.toString();
    }
}

